/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminGUI.java
 *
 * Created on 28/04/2011, 23:14:32
 */

package cliente.gui;

/**
 *
 * @author aers
 */
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import objetos.*;
import util.*;

public class AdminGUI extends javax.swing.JFrame {

    private Usuario usuario;
    private Soquete soquete;
    private ArrayList<Object> objetoPacote;
    private ArrayList<Object> objetoFromServer;

    /** Creates new form AdminGUI */
    public AdminGUI(Usuario usuario) {
        this.usuario = usuario;

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            initComponents();
        }catch(Exception e) {
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bFechar = new javax.swing.JButton();
        bLogout = new javax.swing.JButton();
        jTabbedPane = new javax.swing.JTabbedPane();
        pInicial = new javax.swing.JPanel();
        pGerenciarUsuarios = new javax.swing.JPanel();
        cbGerenciarUsuariosNivelAcesso = new javax.swing.JComboBox();
        lGerenciarUsuariosNivelAcesso = new javax.swing.JLabel();
        lGerenciarUsuariosPontuacao = new javax.swing.JLabel();
        tfGerenciarUsuariosPontuacao = new javax.swing.JTextField();
        tfGerenciarUsuariosEmail = new javax.swing.JTextField();
        lGerenciarUsuariosEmail = new javax.swing.JLabel();
        lGerenciarUsuariosNomeCompleto = new javax.swing.JLabel();
        tfGerenciarUsuariosNomeCompleto = new javax.swing.JTextField();
        tfGerenciarUsuariosMatricula = new javax.swing.JTextField();
        lGerenciarUsuariosMatricula = new javax.swing.JLabel();
        bGerenciarUsuariosAtualizar = new javax.swing.JButton();
        bGerenciarUsuariosRemover = new javax.swing.JButton();
        bGerenciarUsuariosEditarNome = new javax.swing.JButton();
        bGerenciarUsuariosEditarEmail = new javax.swing.JButton();
        bGerenciarUsuariosEditarPontos = new javax.swing.JButton();
        bGerenciarUsuariosEditarMat = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tGerenciarUsuarios = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        tfGerenciarUsuariosUsuarioID = new javax.swing.JTextField();
        pCadastrosPendente = new javax.swing.JPanel();
        pGerenciarPergResp = new javax.swing.JPanel();
        pEnviarPergunta = new javax.swing.JPanel();
        pEditarConfiguracoes = new javax.swing.JPanel();
        lRodape = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Painel de Administração");

        bFechar.setText("Fechar");
        bFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bFecharActionPerformed(evt);
            }
        });

        bLogout.setText("Logout");
        bLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bLogoutActionPerformed(evt);
            }
        });

        jTabbedPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPaneMouseClicked(evt);
            }
        });

        pInicial.setName("Inicio"); // NOI18N

        javax.swing.GroupLayout pInicialLayout = new javax.swing.GroupLayout(pInicial);
        pInicial.setLayout(pInicialLayout);
        pInicialLayout.setHorizontalGroup(
            pInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 699, Short.MAX_VALUE)
        );
        pInicialLayout.setVerticalGroup(
            pInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 342, Short.MAX_VALUE)
        );

        jTabbedPane.addTab("Inicio", pInicial);

        pGerenciarUsuarios.setName("GerenciarUsuarios"); // NOI18N
        pGerenciarUsuarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pGerenciarUsuariosMouseClicked(evt);
            }
        });

        cbGerenciarUsuariosNivelAcesso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { null,"Usuario comum(Aluno)","Usuario Administrador(Professor)" }));

        lGerenciarUsuariosNivelAcesso.setText("Nivel de acesso:");

        lGerenciarUsuariosPontuacao.setText("Pontuacao:");

        tfGerenciarUsuariosPontuacao.setEditable(false);

        tfGerenciarUsuariosEmail.setEditable(false);

        lGerenciarUsuariosEmail.setText("Email:");

        lGerenciarUsuariosNomeCompleto.setText("Nome Completo:");

        tfGerenciarUsuariosNomeCompleto.setEditable(false);

        tfGerenciarUsuariosMatricula.setEditable(false);

        lGerenciarUsuariosMatricula.setText("Matricula:");

        bGerenciarUsuariosAtualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/iconeRefresh.png"))); // NOI18N
        bGerenciarUsuariosAtualizar.setText("Atualizar");
        bGerenciarUsuariosAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGerenciarUsuariosAtualizarActionPerformed(evt);
            }
        });

        bGerenciarUsuariosRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/iconeRemover.png"))); // NOI18N
        bGerenciarUsuariosRemover.setText("Remover Usuário");
        bGerenciarUsuariosRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGerenciarUsuariosRemoverActionPerformed(evt);
            }
        });

        bGerenciarUsuariosEditarNome.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/iconeEditar.png"))); // NOI18N
        bGerenciarUsuariosEditarNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGerenciarUsuariosEditarNomeActionPerformed(evt);
            }
        });

        bGerenciarUsuariosEditarEmail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/iconeEditar.png"))); // NOI18N
        bGerenciarUsuariosEditarEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGerenciarUsuariosEditarEmailActionPerformed(evt);
            }
        });

        bGerenciarUsuariosEditarPontos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/iconeEditar.png"))); // NOI18N
        bGerenciarUsuariosEditarPontos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGerenciarUsuariosEditarPontosActionPerformed(evt);
            }
        });

        bGerenciarUsuariosEditarMat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/iconeEditar.png"))); // NOI18N
        bGerenciarUsuariosEditarMat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGerenciarUsuariosEditarMatActionPerformed(evt);
            }
        });

        tGerenciarUsuarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "UsuarioID", "Matricula", "Nome Completo", "Email", "Pontuacao", "Administrador"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tGerenciarUsuarios.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tGerenciarUsuarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tGerenciarUsuariosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tGerenciarUsuarios);
        tGerenciarUsuarios.getColumnModel().getColumn(0).setMinWidth(80);
        tGerenciarUsuarios.getColumnModel().getColumn(0).setPreferredWidth(80);
        tGerenciarUsuarios.getColumnModel().getColumn(0).setMaxWidth(0);
        tGerenciarUsuarios.getColumnModel().getColumn(1).setMinWidth(80);
        tGerenciarUsuarios.getColumnModel().getColumn(1).setPreferredWidth(80);
        tGerenciarUsuarios.getColumnModel().getColumn(1).setMaxWidth(80);
        tGerenciarUsuarios.getColumnModel().getColumn(4).setMinWidth(100);
        tGerenciarUsuarios.getColumnModel().getColumn(4).setPreferredWidth(100);
        tGerenciarUsuarios.getColumnModel().getColumn(4).setMaxWidth(100);
        tGerenciarUsuarios.getColumnModel().getColumn(5).setMinWidth(100);
        tGerenciarUsuarios.getColumnModel().getColumn(5).setPreferredWidth(100);
        tGerenciarUsuarios.getColumnModel().getColumn(5).setMaxWidth(100);
        tGerenciarUsuarios.getColumnModel().getColumn(5).setCellRenderer(new CheckBoxRenderer());

        jLabel1.setText("UsuarioID:");

        tfGerenciarUsuariosUsuarioID.setEditable(false);

        javax.swing.GroupLayout pGerenciarUsuariosLayout = new javax.swing.GroupLayout(pGerenciarUsuarios);
        pGerenciarUsuarios.setLayout(pGerenciarUsuariosLayout);
        pGerenciarUsuariosLayout.setHorizontalGroup(
            pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
                    .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                        .addComponent(lGerenciarUsuariosNivelAcesso)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbGerenciarUsuariosNivelAcesso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                        .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lGerenciarUsuariosNomeCompleto)
                            .addComponent(lGerenciarUsuariosEmail)
                            .addComponent(lGerenciarUsuariosPontuacao)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tfGerenciarUsuariosEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfGerenciarUsuariosPontuacao, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bGerenciarUsuariosEditarPontos)
                                    .addComponent(bGerenciarUsuariosEditarEmail)))
                            .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pGerenciarUsuariosLayout.createSequentialGroup()
                                        .addComponent(tfGerenciarUsuariosUsuarioID, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lGerenciarUsuariosMatricula)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(tfGerenciarUsuariosMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(tfGerenciarUsuariosNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bGerenciarUsuariosEditarMat)
                                    .addComponent(bGerenciarUsuariosEditarNome))))
                        .addGap(313, 313, 313))
                    .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                        .addComponent(bGerenciarUsuariosAtualizar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bGerenciarUsuariosRemover)))
                .addContainerGap())
        );
        pGerenciarUsuariosLayout.setVerticalGroup(
            pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(tfGerenciarUsuariosUsuarioID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lGerenciarUsuariosMatricula)
                        .addComponent(tfGerenciarUsuariosMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(bGerenciarUsuariosEditarMat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lGerenciarUsuariosNomeCompleto)
                    .addComponent(tfGerenciarUsuariosNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bGerenciarUsuariosEditarNome))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                        .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lGerenciarUsuariosEmail)
                            .addComponent(tfGerenciarUsuariosEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lGerenciarUsuariosPontuacao)
                            .addComponent(tfGerenciarUsuariosPontuacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lGerenciarUsuariosNivelAcesso)
                            .addComponent(cbGerenciarUsuariosNivelAcesso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pGerenciarUsuariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bGerenciarUsuariosAtualizar)
                            .addComponent(bGerenciarUsuariosRemover)))
                    .addGroup(pGerenciarUsuariosLayout.createSequentialGroup()
                        .addComponent(bGerenciarUsuariosEditarEmail)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bGerenciarUsuariosEditarPontos)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(55, Short.MAX_VALUE))
        );

        jTabbedPane.addTab("Gerenciar Usuarios", pGerenciarUsuarios);

        pCadastrosPendente.setName("CadastrosPendente"); // NOI18N

        javax.swing.GroupLayout pCadastrosPendenteLayout = new javax.swing.GroupLayout(pCadastrosPendente);
        pCadastrosPendente.setLayout(pCadastrosPendenteLayout);
        pCadastrosPendenteLayout.setHorizontalGroup(
            pCadastrosPendenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 699, Short.MAX_VALUE)
        );
        pCadastrosPendenteLayout.setVerticalGroup(
            pCadastrosPendenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 342, Short.MAX_VALUE)
        );

        jTabbedPane.addTab("Gerenciar Cadastros Pendentes", pCadastrosPendente);

        pGerenciarPergResp.setName("GerenciarPergResp"); // NOI18N

        javax.swing.GroupLayout pGerenciarPergRespLayout = new javax.swing.GroupLayout(pGerenciarPergResp);
        pGerenciarPergResp.setLayout(pGerenciarPergRespLayout);
        pGerenciarPergRespLayout.setHorizontalGroup(
            pGerenciarPergRespLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 699, Short.MAX_VALUE)
        );
        pGerenciarPergRespLayout.setVerticalGroup(
            pGerenciarPergRespLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 342, Short.MAX_VALUE)
        );

        jTabbedPane.addTab("Gerenciar Perguntas/Respostas", pGerenciarPergResp);

        pEnviarPergunta.setName("EnviarPergunta"); // NOI18N

        javax.swing.GroupLayout pEnviarPerguntaLayout = new javax.swing.GroupLayout(pEnviarPergunta);
        pEnviarPergunta.setLayout(pEnviarPerguntaLayout);
        pEnviarPerguntaLayout.setHorizontalGroup(
            pEnviarPerguntaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 699, Short.MAX_VALUE)
        );
        pEnviarPerguntaLayout.setVerticalGroup(
            pEnviarPerguntaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 342, Short.MAX_VALUE)
        );

        jTabbedPane.addTab("Enviar Pergunta", pEnviarPergunta);

        pEditarConfiguracoes.setName("EditarConfiguracoes"); // NOI18N

        javax.swing.GroupLayout pEditarConfiguracoesLayout = new javax.swing.GroupLayout(pEditarConfiguracoes);
        pEditarConfiguracoes.setLayout(pEditarConfiguracoesLayout);
        pEditarConfiguracoesLayout.setHorizontalGroup(
            pEditarConfiguracoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 699, Short.MAX_VALUE)
        );
        pEditarConfiguracoesLayout.setVerticalGroup(
            pEditarConfiguracoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 342, Short.MAX_VALUE)
        );

        jTabbedPane.addTab("Editar Configurações", pEditarConfiguracoes);

        lRodape.setText("Logado como(Administrador): "+usuario.getNomeCompleto());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lRodape)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 466, Short.MAX_VALUE)
                        .addComponent(bLogout)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bFechar))
                    .addComponent(jTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(bFechar)
                        .addComponent(bLogout))
                    .addComponent(lRodape))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bFecharActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_bFecharActionPerformed

    private void bLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bLogoutActionPerformed
        // TODO add your handling code here:
        this.dispose();
        LoginGUI loginGui = new LoginGUI();
        loginGui.setVisible(true);
    }//GEN-LAST:event_bLogoutActionPerformed

    private void jTabbedPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPaneMouseClicked
        // TODO add your handling code here:
        try {
            if(jTabbedPane.getSelectedComponent().getName().equals("GerenciarUsuarios")) {
                atualizarTGerenciarUsuarios();
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jTabbedPaneMouseClicked

    private void bGerenciarUsuariosEditarMatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGerenciarUsuariosEditarMatActionPerformed
        // TODO add your handling code here:
        tfGerenciarUsuariosMatricula.setEditable(!tfGerenciarUsuariosMatricula.isEditable());
    }//GEN-LAST:event_bGerenciarUsuariosEditarMatActionPerformed

    private void bGerenciarUsuariosEditarNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGerenciarUsuariosEditarNomeActionPerformed
        // TODO add your handling code here:
        tfGerenciarUsuariosNomeCompleto.setEditable(!tfGerenciarUsuariosNomeCompleto.isEditable());
    }//GEN-LAST:event_bGerenciarUsuariosEditarNomeActionPerformed

    private void bGerenciarUsuariosEditarEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGerenciarUsuariosEditarEmailActionPerformed
        // TODO add your handling code here:
        tfGerenciarUsuariosEmail.setEditable(!tfGerenciarUsuariosEmail.isEditable());
    }//GEN-LAST:event_bGerenciarUsuariosEditarEmailActionPerformed

    private void bGerenciarUsuariosEditarPontosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGerenciarUsuariosEditarPontosActionPerformed
        // TODO add your handling code here:
        tfGerenciarUsuariosPontuacao.setEditable(!tfGerenciarUsuariosPontuacao.isEditable());
    }//GEN-LAST:event_bGerenciarUsuariosEditarPontosActionPerformed

    private void tGerenciarUsuariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tGerenciarUsuariosMouseClicked
        // TODO add your handling code here:
        int linha = tGerenciarUsuarios.getSelectedRow();
        tfGerenciarUsuariosUsuarioID.setText(tGerenciarUsuarios.getValueAt(linha,0).toString());
        tfGerenciarUsuariosMatricula.setText(tGerenciarUsuarios.getValueAt(linha,1).toString());
        tfGerenciarUsuariosNomeCompleto.setText(tGerenciarUsuarios.getValueAt(linha,2).toString());
        tfGerenciarUsuariosEmail.setText(tGerenciarUsuarios.getValueAt(linha,3).toString());
        tfGerenciarUsuariosPontuacao.setText(tGerenciarUsuarios.getValueAt(linha,4).toString());
        if((Boolean)tGerenciarUsuarios.getValueAt(linha,5)==true)
            cbGerenciarUsuariosNivelAcesso.setSelectedIndex(2);
        else
            cbGerenciarUsuariosNivelAcesso.setSelectedIndex(1);

        bGerenciarUsuariosRemover.setVisible(true);
    }//GEN-LAST:event_tGerenciarUsuariosMouseClicked

    /*
     * Quando clicar no Painel desseleciona a linha que
     * esta selecionada na tabela, cajo haja, e
     * reseta todos os campos do GerenciarUsuario
     */
    private void pGerenciarUsuariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pGerenciarUsuariosMouseClicked
        // TODO add your handling code here:
        tGerenciarUsuarios.getSelectionModel().clearSelection();

        tfGerenciarUsuariosUsuarioID.setText("");
        tfGerenciarUsuariosMatricula.setText("");
        tfGerenciarUsuariosNomeCompleto.setText("");
        tfGerenciarUsuariosEmail.setText("");
        tfGerenciarUsuariosPontuacao.setText("");
        cbGerenciarUsuariosNivelAcesso.setSelectedIndex(0);
        
        tfGerenciarUsuariosMatricula.setEditable(false);
        tfGerenciarUsuariosNomeCompleto.setEditable(false);
        tfGerenciarUsuariosEmail.setEditable(false);
        tfGerenciarUsuariosPontuacao.setEditable(false);

        bGerenciarUsuariosRemover.setVisible(false);
    }//GEN-LAST:event_pGerenciarUsuariosMouseClicked

    /*
     * Funcao evento quando clicar no botao Atualizar da aba GerenciarUsuarios
     * o sistema vai atualizar os dados do usuario que foi editado
     */
    private void bGerenciarUsuariosAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGerenciarUsuariosAtualizarActionPerformed
        // TODO add your handling code here:
        Usuario userUpdate = new Usuario();
        userUpdate.setUsuarioID(Long.valueOf(tfGerenciarUsuariosUsuarioID.getText()));
        userUpdate.setMatricula(tfGerenciarUsuariosMatricula.getText());
        userUpdate.setNomeCompleto(tfGerenciarUsuariosNomeCompleto.getText());
        userUpdate.setEmail(tfGerenciarUsuariosEmail.getText());
        userUpdate.setPontosExtra(Double.valueOf(tfGerenciarUsuariosPontuacao.getText()));
        if(cbGerenciarUsuariosNivelAcesso.getSelectedIndex()==1)
            userUpdate.setAdmin(false);
        else
            userUpdate.setAdmin(true);
        // --Definindo o protocolo para comunicacao com o servidor
            String cabecalho = "AtualizarUsuario";

            objetoPacote = new ArrayList<Object>();
            objetoPacote.add(cabecalho);
            objetoPacote.add(userUpdate);
            soquete = new Soquete(Constantes.HOST,Constantes.PORTA);
            soquete.enviarPacote(objetoPacote);
            objetoFromServer = (ArrayList<Object>) soquete.receberPacote();
            soquete.close();
        // - Finalizado conexao com o servidor
        cabecalho = (String) objetoFromServer.get(0);
        if(cabecalho.equals("sucesso")) {
            JOptionPane.showMessageDialog(this, "Usuario atualizado com sucesso");
            atualizarTGerenciarUsuarios();
        }
        else {
            JOptionPane.showMessageDialog(this, "Atualizacao de usuario falhou: ");
        }
        
    }//GEN-LAST:event_bGerenciarUsuariosAtualizarActionPerformed

    private void bGerenciarUsuariosRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGerenciarUsuariosRemoverActionPerformed
        // TODO add your handling code here:
        String cabecalho = "RemoverUsuario";
        Usuario usuario = new Usuario();
        usuario.setUsuarioID(Long.valueOf(tfGerenciarUsuariosUsuarioID.getText()));
        // - Fazendo conexao com o servidor
            objetoPacote = new ArrayList<Object>();
            objetoPacote.add(cabecalho);
            objetoPacote.add(usuario);
            soquete = new Soquete(Constantes.HOST,Constantes.PORTA);
            soquete.enviarPacote(objetoPacote);
            objetoFromServer = (ArrayList<Object>) soquete.receberPacote();
            soquete.close();
        // - Finalizado conexao com o servidor
        cabecalho = (String) objetoFromServer.get(0);
        if(cabecalho.equals("sucesso")) {
            JOptionPane.showMessageDialog(this, "Usuario removido com sucesso");
            atualizarTGerenciarUsuarios();
        }
        else {
            JOptionPane.showMessageDialog(this, "Remocao de usuario falhou ");
        }
    }//GEN-LAST:event_bGerenciarUsuariosRemoverActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Usuario usuario = new Usuario();
                usuario.setNomeCompleto("Anderson Eugenio Ribeiro Soares");
                usuario.setEmail("aersandersonsoares@gmail.com");
                usuario.setSenha("aers123");
                new AdminGUI(usuario).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bFechar;
    private javax.swing.JButton bGerenciarUsuariosAtualizar;
    private javax.swing.JButton bGerenciarUsuariosEditarEmail;
    private javax.swing.JButton bGerenciarUsuariosEditarMat;
    private javax.swing.JButton bGerenciarUsuariosEditarNome;
    private javax.swing.JButton bGerenciarUsuariosEditarPontos;
    private javax.swing.JButton bGerenciarUsuariosRemover;
    private javax.swing.JButton bLogout;
    private javax.swing.JComboBox cbGerenciarUsuariosNivelAcesso;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane;
    private javax.swing.JLabel lGerenciarUsuariosEmail;
    private javax.swing.JLabel lGerenciarUsuariosMatricula;
    private javax.swing.JLabel lGerenciarUsuariosNivelAcesso;
    private javax.swing.JLabel lGerenciarUsuariosNomeCompleto;
    private javax.swing.JLabel lGerenciarUsuariosPontuacao;
    private javax.swing.JLabel lRodape;
    private javax.swing.JPanel pCadastrosPendente;
    private javax.swing.JPanel pEditarConfiguracoes;
    private javax.swing.JPanel pEnviarPergunta;
    private javax.swing.JPanel pGerenciarPergResp;
    private javax.swing.JPanel pGerenciarUsuarios;
    private javax.swing.JPanel pInicial;
    private javax.swing.JTable tGerenciarUsuarios;
    private javax.swing.JTextField tfGerenciarUsuariosEmail;
    private javax.swing.JTextField tfGerenciarUsuariosMatricula;
    private javax.swing.JTextField tfGerenciarUsuariosNomeCompleto;
    private javax.swing.JTextField tfGerenciarUsuariosPontuacao;
    private javax.swing.JTextField tfGerenciarUsuariosUsuarioID;
    // End of variables declaration//GEN-END:variables

    private void atualizarTGerenciarUsuarios() {

        // LIMPAR JTABLE ANTES!!

        DefaultTableModel modelo = (DefaultTableModel) tGerenciarUsuarios.getModel();
        modelo.setNumRows(0);

        String cabecalho = "GetUsuariosCadastrados";
        objetoPacote = new ArrayList<Object>();
        objetoPacote.add(cabecalho);
        soquete = new Soquete(Constantes.HOST,Constantes.PORTA);
        soquete.enviarPacote(objetoPacote);
        objetoFromServer = (ArrayList<Object>) soquete.receberPacote();
        soquete.close();

        cabecalho = (String) objetoFromServer.get(0);
        if(cabecalho.equals("sucesso")) {
            // Popula o jTable
            List<Usuario> usuarios = (List) objetoFromServer.get(1);

            Iterator it = usuarios.iterator();
            while(it.hasNext()) {
                Usuario user = (Usuario) it.next();

                System.out.println("Recuperando todos usuarios");

                Vector vetor = new Vector();
                vetor.add(user.getUsuarioID());
                vetor.add(user.getMatricula());
                vetor.add(user.getNomeCompleto());
                vetor.add(user.getEmail());
                vetor.add(0.0);
                vetor.add(user.isAdmin());

                modelo.addRow(vetor);

            }
        }
        else {
            JOptionPane.showMessageDialog(this,"Erro: "+objetoFromServer.get(1));
        }
    }

}
